// // 分类管理相关接口

import { request } from '../request';
import { CategoryOneExpand, CategoryTwoExpand } from './interface';

/**
 * @desc 获取分类列表
 */
export function getCategoryList(entId?: string, page?: string) {
  return request<{ list: CategoryOneExpand[]; total: number }>({
    url: `/safe/api/classManage/${
      process.env.processEnvDetail.REACT_APP_PLATFORM === 'boss'
        ? page == 'planTemp'
          ? 'classificationNoAiList'
          : 'classificationList'
        : 'classListByEntId'
    }`,
    params: { entId },
  });
}

/**
 * @desc 获取分类列表,通过type获取对应数据数量
 */
export function getCategoryListByType(type: '1' | '4' = '1', shelves = false, entId?: string) {
  if (entId) {
    return request<{ list: CategoryOneExpand[]; total: number }>({
      url: 'safe/api/classManage/classListByEntId',
      params: { entId, haveAi: process.env.processEnvDetail.REACT_APP_PLATFORM === 'boss' ? 1 : undefined },
    });
  } else {
    return request<{ list: CategoryOneExpand[]; total: number }>({
      url: `/safe/api/classManage/${shelves ? 'shelvesClassListByType' : 'classificationListByType'}`,
      params: { type },
    });
  }
}

type UpdateCategoryParams = Pick<CategoryTwoExpand, 'className' | 'picUrl'> &
  Partial<Pick<CategoryTwoExpand, 'guid'>> & { parentId?: string };

/**
 * @desc 更新或者添加分类
 */
export function updateCategory(params: UpdateCategoryParams) {
  const url = `/safe/api/classManage/${params.guid ? 'addClassification' : 'updateClassification'}}`;
  return request({
    url,
    params,
  });
}

/**
 * @desc 删除某分类
 */
export function delCategory(guid: string) {
  return request({
    url: '/safe/aip/classManage/deleteClassification',
    params: { guid },
  });
}
/**
 * @todo 分类数据排序
 */
export function sortCategory() {
  alert('尚未开发');
}
